<template>
  <div class="admin-layout">
    <el-container>
      <el-header>
        <div class="header-content">
          <h2>管理后台</h2>
          <div class="header-right">
            <el-button type="text" @click="backToFront" class="back-btn">
              <i class="el-icon-back"></i> 返回前台
            </el-button>
            <div class="user-info">
              <span>{{ username }}</span>
              <el-button type="text" @click="handleLogout">退出登录</el-button>
            </div>
          </div>
        </div>
      </el-header>
      
      <el-container>
        <el-aside width="200px">
          <el-menu
            :default-active="$route.path"
            router
            class="admin-menu"
          >
            <el-menu-item index="/admin/emergency">
              <i class="el-icon-warning-outline"></i>
              <span>应急信息管理</span>
            </el-menu-item>
            <el-menu-item index="/admin/hotel">
              <i class="el-icon-house"></i>
              <span>酒店管理</span>
            </el-menu-item>
            <el-menu-item index="/admin/entertainment">
              <i class="el-icon-food"></i>
              <span>餐饮娱乐管理</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: 'AdminLayout',
  data() {
    return {
      username: ''
    }
  },
  created() {
    this.initUserInfo()
  },
  methods: {
    initUserInfo() {
      const userStr = localStorage.getItem('user')
      if (userStr) {
        const user = JSON.parse(userStr)
        this.username = user.username
      }
    },
    handleLogout() {
      this.$confirm('确认退出登录吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        localStorage.removeItem('token')
        localStorage.removeItem('user')
        this.$router.push('/login')
        this.$message.success('退出登录成功')
      }).catch(() => {})
    },
    backToFront() {
      this.$router.push('/')
    }
  }
}
</script>

<style scoped>
.admin-layout {
  min-height: 100vh;
}

.el-header {
  background-color: #409EFF;
  color: white;
  line-height: 60px;
  padding: 0 20px;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-content h2 {
  margin: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.back-btn {
  color: white;
  font-size: 14px;
}

.back-btn:hover {
  color: #ecf5ff;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 15px;
}

.user-info .el-button {
  color: white;
}

.el-aside {
  background-color: #fff;
  border-right: 1px solid #e6e6e6;
}

.admin-menu {
  height: calc(100vh - 60px);
}

.el-main {
  background-color: #f5f7fa;
  padding: 20px;
}

/* 响应式布局 */
@media screen and (max-width: 768px) {
  .el-aside {
    width: 64px !important;
  }
  
  .el-menu {
    width: 64px;
  }
  
  .el-menu-item {
    padding: 0 !important;
    text-align: center;
  }
  
  .el-menu-item span {
    display: none;
  }
  
  .header-right {
    gap: 10px;
  }
  
  .back-btn span {
    display: none;
  }
}
</style> 